using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Box2D.XNA;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Entity
{
    class WindBlade:PhysicSprite
    {
        Vector2 v=Vector2.Zero;

        public enum ShotDirection {
        up,left,right,down
        }

        public float Velocity { get; set; }

        public WindBlade() {
            textureName = "singleStage2Boss/blade_of_wind";
            Physic_Type = PhysicType.WindBlade;
        }

        public override void OnLoad()
        {
            base.OnLoad();
            this.SetAnimation(new Point(1, 1),new int[] {0});
        }

        public override void OnCreatBody(World world, PhysicConnectManager connectManager)
        {
            base.OnCreatBody(world, connectManager);
            IsSensor = true;
            Filter f = new Filter();
            f.categoryBits = Constants.CategoryBitsEnemy;
            f.maskBits = Constants.MaskBitsEnemy;
            Filter = f;
        }

        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            body.SetLinearVelocity(v);
        }
        
        public void Shot(ShotDirection direction) {

             v = Vector2.Zero;
             float mtp = Constants.MeterToPixal/10;
            switch (direction) {
                case ShotDirection.down:
                    v.Y = -Velocity / mtp;
                    body.Rotation = Functional.ToRadian(-90);
                    break;
                case ShotDirection.left:
                    v.X = -Velocity / mtp;
                    body.Rotation = Functional.ToRadian(180);
                    break;
                case ShotDirection.right:
                    v.X = Velocity / mtp;
                    body.Rotation = Functional.ToRadian(0);
                    break;
                case ShotDirection.up:
                    v.Y = Velocity / mtp;
                    body.Rotation = Functional.ToRadian(90);
                    break;
            }
        }

        public override void BeginContact(PhysicSprite other)
        {
            base.BeginContact(other);
            if (other.Physic_Type == PhysicType.Player) {
                SingleGamePlayer player = (SingleGamePlayer)other;
                player.MinusLifeTime(1);
            }
        }

        public bool IsOutOfView() {
            Vector2 pos = Vector2.Transform(Position, Projection);
            return pos.X < -100 || pos.X > 580 || pos.Y < -100 || pos.Y > 900;
        }

    }
}
